<template>
<div>
  <h1>注册页面</h1>
  <el-card>
    <el-form>
      <el-form-item label="用户名"><el-input v-model="user.username" placeholder="请输入用户名"></el-input>
      </el-form-item>
      <el-form-item label="密码"><el-input v-model="user.password" placeholder="请输入密码"></el-input>
      </el-form-item>
      <el-form-item label="昵称"><el-input v-model="user.nickname" placeholder="请输入昵称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="reg()">注册</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</div>
</template>

<script>
export default {
  name: "RegView",
  data() {
    return {
      user: {username: "",password:"",nickname:""}
    }
  },
  methods: {
    reg() {
      //发出注册异步请求
      this.axios.post("http://localhost:8080/v1/users/reg",this.user)
          .then((response)=>{
            //response代表响应对象 response.data服务器响应的数据
            //response.data=服务器响应的JsonResult对象
            if (response.data.code==1){
              this.$message.success('注册成功!');
              this.$router.push('/');
            }else{
              this.$message.error(response.data.msg);
            }
          })
    }
  },
}
</script>

<style scoped>

</style>